package com.orangelife.mobile.util;

import java.util.List;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;


/**
 * 发短信服务
 * 
 * @author chenxiang
 * 
 */
public class SmsHelper {

	private SmsManager smsManager;
	private PendingIntent sentIntent;
	private Context myContext;

	public SmsHelper(Context context) {
		myContext = context;
		smsManager = SmsManager.getDefault();
		sentIntent = PendingIntent.getBroadcast(context, 0, new Intent(), 0);
	}

	public void sendSms(String phone, String content) {
		if (content.length() >= 70) {
			// 短信字数大于70，自动分条
			List<String> ms = smsManager.divideMessage(content);

			for (String str : ms) {
				// 短信发送
				smsManager.sendTextMessage(phone, null, str, sentIntent, null);
			}
		} else {
			smsManager.sendTextMessage(phone, null, content, sentIntent, null);
		}

		ToastHelper.displayToastLong(myContext, "发送成功");
	}
}
